#激活触发器
scoreboard players enable @a[tag=!DieOutAgree] DieOutTrigger

execute store success score AlivePlayerCount DieOutInfo if entity @a[tag=DieOutAgree]

#输入触发：同意对局
execute as @a[tag=!DieOutAgree] unless score @s DieOutTrigger matches 0 run tellraw @a [{"text":"[大逃杀] ","color":"red","bold":true},{"selector":"@s","color":"green","bold":false},{"text":" 已同意，同意人数：","color":"white","bold":false},{"color":"aqua","score":{"objective":"DieOutInfo","name":"AlivePlayerCount"},"bold":false},{"text":" 在线人数：","color":"white","bold":false},{"color":"aqua","score":{"objective":"System","name":"OnlinePlayerCount"},"bold":false},{"text":"\n需要当前在线人数的一半，即可开启一局大逃杀游戏","color":"gray","bold":false}]
execute as @a[tag=!DieOutAgree] unless score @s DieOutTrigger matches 0 run tag @s add DieOutAgree
execute as @a unless score @s DieOutTrigger matches 0 run scoreboard players set @s DieOutTrigger 0


# #输入触发：不同意对局
# execute as @a[scores={DieOutTrigger=-1}] run tellraw @a [{"text":"[大逃杀] ","color":"red","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"selector":"@s","color":"green","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":" 已拒绝","color":"red","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":"本次对局","color":"red","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":" 同意人数：","color":"white","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"color":"aqua","score":{"objective":"DieOutInfo","name":"AlivePlayerCount"},"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false}]
# execute as @a[scores={DieOutTrigger=-1}] run tag @s remove DieOutAgree
# scoreboard players set @a[scores={DieOutTrigger=-1}] DieOutTrigger 0


##当已同意人数等于在线人数时快速开始游戏
execute if score AlivePlayerCount DieOutInfo = OnlinePlayerCount System if score TimeClock DieOutInfo matches 4.. run tellraw @a [{"text":"[大逃杀] ","color":"red","bold":true},{"selector":"@s","color":"green","bold":false},{"text":"所有玩家已同意，即将在 ","color":"white","bold":false},{"text":"3","color":"aqua","bold":false},{"text":"s 后进入选择英雄","color":"white","bold":false}]
execute if score AlivePlayerCount DieOutInfo = OnlinePlayerCount System if score TimeClock DieOutInfo matches 4.. run scoreboard players set TimeClock DieOutInfo 3
##当TimeClock为0时，比较已同意人数与在线人数的一半
execute if score TimeClock DieOutInfo matches 0 run scoreboard players operation OnlineHelf System /= OnlinePlayerCount System
execute if score TimeClock DieOutInfo matches 0 run scoreboard players operation OnlineHelf System /= SystemHelf System
execute if score TimeClock DieOutInfo matches 0 if score OnlineHelf System matches 0 run scoreboard players set OnlineHelf System 1
#   将所有人恢复观战模式 若此玩家还在对局中则回馈一张体验卡
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run scoreboard players add @a[tag=Alive] DataEXCard 1
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run scoreboard players set @a SystemDeath 2
#   将右侧计分板显示为大逃杀对局信息
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run scoreboard objectives setdisplay sidebar DieOutInfo
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run tellraw @a [{"text":"[大逃杀] ","color":"red","bold":true},{"text":"已开启大逃杀对局，请选择您的","color":"white","bold":false},{"text":"英雄","color":"light_purple","bold":false},{"text":"\n未选择视为不加入本次对局","color":"gray","bold":false}]
#   初始化下一阶段
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run scoreboard players set IsTheDieOutGame SystemAdmin 2
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run scoreboard players set UpdateCount DieOutInfo 0
execute if score TimeClock DieOutInfo matches 0 if score AlivePlayerCount DieOutInfo > OnlineHelf System run scoreboard players set TimeClock DieOutInfo 60
##——————————————————————————————————————————————————————————————————————————————————————

#不满足则通报并停止
execute if score TimeClock DieOutInfo matches 0 run tellraw @a [{"text":"[大逃杀] ","color":"red","bold":true},{"text":"对局启动失败，同意人数不足","color":"white","bold":false},{"text":"\n已同意人数：","color":"white","bold":false},{"color":"aqua","score":{"objective":"DieOutInfo","name":"AlivePlayerCount"},"bold":false},{"text":" 需要人数大于：","color":"white","bold":false},{"color":"aqua","score":{"objective":"System","name":"OnlineHelf"},"bold":false}]
execute if score TimeClock DieOutInfo matches 0 run function nw:system/system_module/dieout_util_gameover